package ch.zhan.objectivea.activity.adapter;

import java.util.List;

import ch.zhan.objectivea.R;
import ch.zhan.objectivea.activity.buisiness.Couche;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CoucheAdapter extends BaseAdapter {
    
    private Activity activity;
    private List<Couche>  data;
    private static LayoutInflater inflater=null;
    
    public CoucheAdapter(Activity a, List<Couche> d) {
        activity = a;
        data=d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.list_row, null);

        TextView epaisseur = (TextView)vi.findViewById(R.id.epaisseur); // title
        TextView subtitle = (TextView)vi.findViewById(R.id.subtitle); // artist name
        
        Couche c = data.get(position);

        epaisseur.setText(String.valueOf(c.getEpaisseur()) + " cm");
        subtitle.setText(c.getLibelle());
        return vi;
    }
    
    public void add(Couche couche) {
    	data.add(couche);
        notifyDataSetChanged();
    }
    
    public void remove(int position) {
    	data.remove(position);
        notifyDataSetChanged();
    }
}